package com.misboot.document.controller;

import com.misboot.document.service.FileService;
import com.misboot.document.utils.minio.MinioUtil;
import com.misboot.document.utils.wps.Token;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

/**
 * @MethodName
 * @Description  用户实现获取wps可预览URL
 * @Param null
 * @Return
 * @Author 湖南佐佑时代科技有限公司<service@zuoyo.com>
 * @Date 2020-10-20 13:16
 */
@Controller
@RequestMapping("/wps")
public class WpsController extends DocumentBaseController {

    static Logger logger = LoggerFactory.getLogger(WpsController.class);

    @Autowired
    private FileService fileService;


    /**
     * 通过fileId获取wpsUrl以及token
     *
     * @param fileId 文件id
     * @return token（包含url）
     */
    @ResponseBody
    @PostMapping("/getViewUrlDbPath")
    public Object getViewUrlDbPath(String fileId, String userId, String bucket) {
        logger.info("getViewUrlDbPath：fileId={},userId={}", fileId, userId);
        Token t = fileService.getViewUrl(fileId,  userId, true, bucket);
        HashMap var3 = new HashMap();
        if (t != null) {
            var3.put("statusCode", 200);
            var3.put("message", "编辑");
            var3.put("Token", t);
            return var3;
        } else {
            var3.put("statusCode", 300);
            var3.put("message", "新建");
            return var3;
        }
    }


    /**
     * 获取网络文件预览URL
     *
     * @param fileUrl fileUrl
     * @return t
     */
    @ResponseBody
    @RequestMapping("/getViewUrlWebPath")
    public Object getViewUrlWebPath(String fileUrl,String uuid,String uploadType,String permission) {
        logger.info("getViewUrlWebPath：fileUrl={}", fileUrl);
        Token t = fileService.getViewUrl(fileUrl, true,uuid, uploadType,permission);
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "操作提示");
        var3.put("message", "获取成功");
        var3.put("Token", t);
        return var3;
    }


    /**
     * 通过wps官方模版新建文件
     * template值 {"word", "excel", "ppt"}
     */
    @ResponseBody
    @RequestMapping("createTemplateFile")
    public Object createTemplateFile(
            String template, String uuid, String bucket
    ) {
        String puuid = uuid;
        Object newUrl = fileService.createTemplateFile(template, puuid, bucket);
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "操作提示");
        var3.put("message", "获取成功");
        var3.put("newUrl",newUrl);
        return var3;
    }

    /**
     * 转换文件
     *
     * @param srcUri     文件url
     * @param exportType 到处类型
     */
    @ResponseBody
    @RequestMapping("convert")
    public Object convert(String taskId , String srcUri, String exportType) {
        fileService.convertFile(taskId, srcUri, exportType);
        return success("转换文件成功");
    }



    /**
     * 获取转换文件
     *
     * @param taskId 任务id，由convert接口生成
     */
    @ResponseBody
    @GetMapping("getConvert")
    public Object getConvert(String taskId) {
        Object res = fileService.getConvertQueryRes(taskId);
        return success("获取转换文件");
    }

}
